const baseUrl = 'http://localhost:8080'; 

function request({ url, method = 'GET', data = {}, header = {} }) {
  const token = wx.getStorageSync('token');
  return new Promise((resolve, reject) => {
    wx.request({
      url: baseUrl + url,
      method,
      data,
      header: {
        'content-type': 'application/json',
        ...(token ? { 'Authorization': token } : {}),
        ...header
      },
      success(res) {
        resolve(res.data);
      },
      fail(err) {
        reject(err);
      }
    });
  });
}

module.exports = {
  get(url, data = {}, header = {}) {
    return request({ url, method: 'GET', data, header });
  },
  post(url, data = {}, header = {}) {
    return request({ url, method: 'POST', data, header });
  },
  put(url, data = {}, header = {}) {
    return request({ url, method: 'PUT', data, header });
  },
  delete(url, data = {}, header = {}) {
    return request({ url, method: 'DELETE', data, header });
  },
  request
}; 